--debug log
do
	local test = pvp	
    local _debugFrame
	local backlog = {}

------------------------------------------------------------------------------
------------------------------------------------------------------------------   
    local function CreateDebugLogFrame() 
		if not pvp.frame then return nil end
		
        local frame = CreateFrame("ScrollingMessageFrame",nil,pvp.frame)
        frame:SetFrameStrata("BACKGROUND")
        frame:SetWidth(350)
        frame:SetHeight(100)		
        frame:SetFontObject("GameFontNormal")              
        frame:SetFading(false)   
        frame:SetInsertMode("BOTTOM")
		frame:SetMaxLines(1000)
		frame:SetJustifyH("LEFT")
       
        --mouse wheel scroll
        frame:SetScript("OnMouseWheel", function(self,delta)
				if delta > 0 then
					self:ScrollUp()
				elseif delta < 0 then
					self:ScrollDown()
				end
			end 
		)		
       
        --background texture
        frame.bg = frame:CreateTexture(nil,"BACKGROUND")
        frame.bg:SetTexture(0,0,0,.66)
        frame.bg:SetAllPoints()
		
		frame:Hide()
       
		_debugFrame = frame
        return frame
    end
   
------------------------------------------------------------------------------
------------------------------------------------------------------------------   
    function pvp:Log(str)
		tinsert(backlog,str)
        local frame = _debugFrame or CreateDebugLogFrame()		
		if not frame then return end
		for i,p in ipairs(backlog) do
			frame:AddMessage(p,1,1,1)
		end
		backlog = {}
    end 


------------------------------------------------------------------------------
------------------------------------------------------------------------------   
    function pvp:ToggleDebugLog()
        local frame = _debugFrame or CreateDebugLogFrame()
		if not frame then return end
        if frame:IsVisible() then
            frame:Hide()
        else
			frame:SetPoint("TOPLEFT",pvp.frame:GetWidth()+1,0)
            frame:Show()
        end
    end
end --eof